﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.zoo.ui {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import Classes.*;

    public class ZooEnclosureSlot extends Sprite {

        private var m_animalDefinition:Item;
        private var m_animalAsset:DisplayObject;
        private var m_animalHolder:Sprite;
        private var m_backgroundHolder:Sprite;
        private var m_background:Sprite;
        private var m_btnClose:SimpleButton;
        private var m_index:int;
        private var m_currAnimalStickerUrl:String;

        public function ZooEnclosureSlot(){
            var _local1:DisplayObject = new (ZooDialog.assetDict["enclosure_box"])();
            this.m_btnClose = new SimpleButton(new (ZooDialog.assetDict["enclosure_close_btn_up"])(), new (ZooDialog.assetDict["enclosure_close_btn_over"])(), new (ZooDialog.assetDict["enclosure_close_btn_up"])(), new (ZooDialog.assetDict["enclosure_close_btn_over"])());
            this.m_btnClose.x = (_local1.width - this.m_btnClose.width);
            this.m_btnClose.addEventListener(MouseEvent.CLICK, this.onCloseClick, false, 0, true);
            this.hideCloseBtn();
            this.m_background = new Sprite();
            this.m_background.addChild(_local1);
            this.m_background.addChild(this.m_btnClose);
            this.m_backgroundHolder = new Sprite();
            this.m_backgroundHolder.addChild(this.m_background);
            addChild(this.m_backgroundHolder);
            this.m_animalHolder = new Sprite();
            addChild(this.m_animalHolder);
            this.addEventListener(MouseEvent.MOUSE_OVER, this.onMouseOver, false, 0, true);
            this.addEventListener(MouseEvent.MOUSE_OUT, this.onMouseOut, false, 0, true);
        }
        public function get animalDefinition():Item{
            return (this.m_animalDefinition);
        }
        public function get isOccupied():Boolean{
            return (!((this.m_animalDefinition == null)));
        }
        public function get index():int{
            return (this.m_index);
        }
        public function set index(_arg1:int):void{
            this.m_index = _arg1;
        }
        public function addAnimal(_arg1:String):void{
            this.m_animalDefinition = Global.gameSettings.getItemByName(_arg1);
            if (this.m_animalDefinition){
                this.m_currAnimalStickerUrl = this.m_animalDefinition.getImageByName("editor");
                LoadingManager.loadFromUrl(this.m_currAnimalStickerUrl, {
                    priority:LoadingManager.PRIORITY_HIGH,
                    completeCallback:this.onAnimalAssetLoadComplete
                });
            };
            this.hideBackground();
            this.showCloseBtn();
        }
        public function removeAnimal():void{
            if (((this.m_animalAsset) && (this.m_animalAsset.parent))){
                this.m_animalAsset.parent.removeChild(this.m_animalAsset);
            };
            this.m_animalDefinition = null;
            this.showBackground();
            this.hideCloseBtn();
        }
        private function showBackground():void{
            this.m_background.alpha = 1;
            this.m_background.mouseEnabled = (this.m_background.mouseChildren = true);
        }
        private function hideBackground():void{
            this.m_background.alpha = 0;
            this.m_background.mouseEnabled = (this.m_background.mouseChildren = false);
        }
        private function hideCloseBtn():void{
            this.m_btnClose.alpha = 0;
            this.m_btnClose.mouseEnabled = false;
        }
        private function showCloseBtn():void{
            this.m_btnClose.alpha = 1;
            this.m_btnClose.mouseEnabled = true;
        }
        private function onAnimalAssetLoadComplete(_arg1:Event):void{
            var _local2:LoaderInfo = (_arg1.currentTarget as LoaderInfo);
            while (this.m_animalHolder.numChildren) {
                this.m_animalHolder.removeChildAt(0);
            };
            if (this.isOccupied){
                this.m_animalAsset = _local2.content;
                this.m_animalAsset.x = ((this.m_background.width - this.m_animalAsset.width) * 0.5);
                this.m_animalAsset.y = (this.m_background.height - this.m_animalAsset.height);
                this.m_animalHolder.addChild(this.m_animalAsset);
            };
        }
        private function onMouseOver(_arg1:MouseEvent):void{
            if (this.isOccupied){
                this.showBackground();
            };
        }
        private function onMouseOut(_arg1:MouseEvent):void{
            if (this.isOccupied){
                this.hideBackground();
            };
        }
        private function onCloseClick(_arg1:MouseEvent):void{
            dispatchEvent(new Event(Event.CLOSE));
        }

    }
}//package Modules.zoo.ui 
